package com.relax.start.config;

import com.relax.start.MyStartService;
import com.relax.start.MyStartServiceProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnClass(MyStartService.class)
@EnableConfigurationProperties(MyStartServiceProperties.class)
public class MyStartServiceAutoConfig {

    @Autowired
    private MyStartServiceProperties myStartServiceProperties;

    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnProperty(prefix = "example.service", value = "enabled", havingValue = "true")
    public MyStartService myStartService() {
        MyStartService myStartService = new MyStartService();
        myStartService.setPrefix(myStartServiceProperties.getPrefix());
        myStartService.setSuffix(myStartServiceProperties.getSuffix());
        return myStartService;
    }
}
